package com.clqteam.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.clqteam.dao.SelectDailyReportDao;
import com.clqteam.model.DailyReport;
import com.clqteam.util.JDBCutil;
/**
 * 
 * @author CLQ
 *
 */
public class SelectDailyReportDaoImpl implements SelectDailyReportDao{

	@Override
	public List<DailyReport> getDailyReportInfo(int page, int rows, String time1, String time2,String emName) {
		 List<DailyReport> dailyReport=new ArrayList<DailyReport>();
		  StringBuffer sql=new StringBuffer();
		  sql.append(" SELECT s_dailyreport.drId,s_dailyreport.drTime,s_dailyreport.drInfo,s_dailyreport.eName");
		  sql.append(" FROM s_dailyreport");
		  sql.append("  WHERE (s_dailyreport.drTime BETWEEN ? AND ?)");
		  sql.append(" AND s_dailyreport.eName=?");
		  sql.append(" LIMIT ?,?");
		  Connection con=JDBCutil.getConnection();
		  try {
			  PreparedStatement  pst=con.prepareStatement(sql.toString());
			  pst.setString(1,time1);
			  pst.setString(2, time2);
			  pst.setString(3, emName);
			  pst.setInt(4, (page-1)*rows);
			  pst.setInt(5, rows);
			  ResultSet rs=pst.executeQuery();
			   while (rs.next()) {
				DailyReport day=new DailyReport();
				 day.setDrId(rs.getInt("drId"));
				day.setDrTime(rs.getString("drTime"));
				day.setDrInfo(rs.getString("drInfo"));
				day.seteName(rs.getString("eName"));
				dailyReport.add(day);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dailyReport;
	}

	@Override
	public int getDailyReportCount(String time1,String time2,String emName) {
		 int count=0;
		 StringBuffer sql=new StringBuffer();
		  sql.append(" SELECT COUNT(s_dailyreport.drId)AS dcount FROM s_dailyreport");
		  sql.append("  WHERE (s_dailyreport.drTime BETWEEN ? AND ?)");
		  sql.append(" AND s_dailyreport.eName=?");
		  Connection con=JDBCutil.getConnection();
		 try {
			 PreparedStatement pst=con.prepareStatement(sql.toString());
			 pst.setString(1, time1);
			 pst.setString(2, time2);
			 pst.setString(3, emName);
			 ResultSet rs=pst.executeQuery();
			 if (rs.next()) {
				 count=rs.getInt("dcount");
				 
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
		return count;
	}

}
